package com.oocl.products.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.oocl.products.dao.UserDao;
import com.oocl.products.pojo.User;
import com.oocl.products.util.DBHelper;

public class UserDaoImpl implements UserDao {

	public User queryUserByNameAndPwd(String name, String pwd) {
		Connection conn = DBHelper.getConnectionWithDs();
		User user = null;
		String sql = "select * from users where name = ? and pwd = ? ";
		PreparedStatement pst = null;
		ResultSet rst = null;
		try {
			pst =  conn.prepareStatement(sql);
			pst.setString(1, name);
			pst.setString(2, pwd);
			rst = pst.executeQuery();
			while(rst.next()){
				user = new User();
				user.setId(rst.getString(1));
				user.setName(rst.getString(2));
				user.setPwd(rst.getString(3));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBHelper.close(pst, rst, conn);
		}
		return user;
	}

}
